//
//  BIZDefaultSortView.m
//  biz
//
//  Created by zhangfuwei on 2017/4/10.
//  Copyright © 2017年 jieshuibao. All rights reserved.
//

#import "BIZDefaultSortView.h"

@implementation BIZDefaultSortView{
    UIButton         *_defaultSortBtn;
    UIButton         *_newestSortBtn;
    UIImageView     *_defaultSortSelectedImgV;
    UIImageView     *_newestSortSelectedImgV;

}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self loadUI];
    }
    return self;
}

- (void)loadUI {
    self.backgroundColor = [UIColor whiteColor];
    CGFloat imgVW = 14;
    CGFloat imgVH = 10;
    CGFloat btnH = 50;
    CGFloat btnW = Main_Screen_Width - imgVW-10;
    
    _defaultSortBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, btnW,btnH)];
    [_defaultSortBtn setTitle:@"默认排序" forState:UIControlStateNormal];
    [_defaultSortBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _defaultSortBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _defaultSortBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    _defaultSortBtn.tag = 1;
    [_defaultSortBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    _newestSortBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, btnH, btnW,btnH)];
    [_newestSortBtn setTitle:@"最新" forState:UIControlStateNormal];
    [_newestSortBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _newestSortBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    _newestSortBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    _newestSortBtn.tag = 2;
    [_newestSortBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    
    
    _defaultSortSelectedImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"correct"]];
    
    _defaultSortSelectedImgV.frame = CGRectMake(btnW, (btnH-imgVH)/2, imgVW, imgVH);

    _newestSortSelectedImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"correct"]];
    _newestSortSelectedImgV.frame = CGRectMake(btnW, btnH + (btnH-imgVH)/2, imgVW, imgVH);
        
    [self addSubview:_defaultSortBtn];
    [self addSubview:_newestSortBtn];
    [self addSubview:_defaultSortSelectedImgV];
    [self addSubview:_newestSortSelectedImgV];
}
- (void)setIsDefaultType:(BOOL)isDefaultType {
    
    _isDefaultType = isDefaultType;
    if (isDefaultType) {
        [_newestSortSelectedImgV setImage:nil];
    }
    _defaultSortSelectedImgV.hidden = !isDefaultType;
    _newestSortSelectedImgV.hidden = isDefaultType;

}

- (void)clickBtn:(UIButton*) btn {
    
    self.block ? self.block(btn.tag):nil;
}

@end
